package cn.quevo.core.file.enums;

import cn.quevo.core.enums.EnumsInterface;
import cn.quevo.core.file.draw.AbstractCodeDraw;
import cn.quevo.core.file.draw.impl.*;

/**
 * 文件类型枚举
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/07/09 13:55:32
 * @Copyright 东方浩星（北京）传媒科技有限公司版权所有.All Rights Reserved.
 */
public enum ImageCodeType {
    NOISE(NoiseDraw.class),
    RANDOM_LINE(RandomLineDraw.class),
    LEFT_LINE(LeftLineDraw.class),
    RIGHT_LINE(RightLineDraw.class),
    H_LINE(HLineDraw.class),
    V_LINE(VLineDraw.class),
    NONE(null);
    private Class validateClass;

    private ImageCodeType(Class validateClass) {
        this.validateClass = validateClass;
    }

    public AbstractCodeDraw getValidateClass() {
        try {
            return (AbstractCodeDraw) this.validateClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static ImageCodeType format(String name) {
        try {
            return ImageCodeType.valueOf(name.toUpperCase());
        } catch (Exception e) {
            return ImageCodeType.NONE;
        }
    }
}
